<?php

session_start();

include "webmaster_connect.php";

$page_permission = 2;

include "webmaster_check_login.php";

//If no product ID is posted then use the active product ID
if(isset($_POST['product_row_id']))
	
	{
	$product_row_id = $_POST['product_row_id'];} else {$product_row_id = $_SESSION['active_product_id'];
	}

$product_query = "SELECT * FROM saddles WHERE id = $product_row_id";
$product_result = mysql_query($product_query);
while($product_row = mysql_fetch_array($product_result))

	{
	
	$product_id 			= $product_row['product_id'];
	$product_type 			= $product_row['product_type'];
	$product_catagory 		= $product_row['product_catagory'];
	$product_sub_catagory	= $product_row['product_sub_catagory'];
	$product_name 			= $product_row['product_name'];
	$product_status 		= $product_row['product_status'];
	$product_cost 			= $product_row['product_cost'];
	$product_description	= $product_row['product_description'];
	$product_make 			= $product_row['product_make'];
	$product_colour 		= $product_row['product_colour'];
	$product_size			= $product_row['product_size'];
	$product_offer 			= $product_row['product_offer'];

	}
 
//Hide the upload image section if the saddle status = SOLD
if ($product_status == "Sold")

	{
	$display = "hidden";} else {$display = "visible";
	}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Amend products</title>

<style type="text/css">
body {
	background-image: url(../images/wood.jpg);
	background-repeat: repeat-x;
	margin: 0px;
	background-position: left top;
	background-attachment: fixed;
	background-color: #000000;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 0px;
	padding-left: 0px;
}
</style>
<link href="../css/webmaster_amend_products.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="page_container">

<?php 

include "../admin_files/webmaster_header.php";
include "../admin_files/webmaster_navigation.php" 

?>

	<div id="content_container">

	<h1>Edit product details: <?php echo $_COOKIE["save_message"]; ?></h1>

	<form action="webmaster_process_amend_product.php" method="post" name="add_product" id="add_product">

	<h2>Product details</h2>
	<input name="product_row_id" type="text" value = "<?php if($product_row_id != ""){echo $product_row_id;} else {echo $_SESSION['active_product_id'];} ?>" readonly="readonly"/>
	<input name="product_name" type="text" class="product_name" value = '<?php echo $product_name ?>' readonly="readonly"/>
	<input name="product_id" type="hidden" class="product_id" value = '<?php echo $product_id ?>'/>

	<select name="product_status">

	<?php 

	$status_query = "SELECT * FROM product_statuses WHERE active = 1";
	$status_result = mysql_query($status_query);
	while($status_row = mysql_fetch_array($status_result))

		{
		if ($product_status == $status_row['status'])
			
			{
			$selected = "Selected";
			} 
			
			else 
			
			{
			$selected = "";
			}
	
		echo '<option '.$selected.' value="'.$status_row['status'].'">'.$status_row['status'].'</option>';
	
		}


 	?>

	</select>

	<input name="product_cost" type="text" value = "<?php echo $product_cost ?>"/>
	<textarea class="description_box" name="product_description" cols="" rows="" ><?php echo $product_description ?></textarea>

	<h2>Product additional information</h2>
	<input name="product_make" type="text" value = "<?php echo $product_make ?>" placeholder="Saddle make"/>
	<input name="product_colour" type="text" value = "<?php echo $product_colour ?>" placeholder="Saddle colour"/>
	<input name="product_size" type="text" value = "<?php echo $product_size ?>" placeholder="Saddle size"/>
	<input name="product_offer" type="text" value = "<?php echo $product_offer ?>" placeholder="Special offer"/>

	<input name="add_button" type="submit" class="<? echo $display ?>" value="Update details" />

	</form>

	</div>
	<!--content_container-->
    
	<div class="<?php echo $display ?>" id="content_container">

	<h2>Product images</h2>

	<form action="webmaster_process_upload_file.php" method="post" enctype="multipart/form-data" name="uploadFile" id="uploadFile">

	<input id="uploadField" type="file" name="uploaded_file">
	<input name="product_id" type="hidden" value="<?php echo $product_row_id ?>">

	<select name="image_number">
		<option value="1" >1</option>
		<option value="2" >2</option>
		<option value="3" >3</option>
		<option value="4" >4</option>
	</select>
	
    <input id="button" class="save_button" name="uploadProductImage" type="submit" value="Upload Image">
  	 
	</form>


	<table width="950" border="0">
		<tr>
			<td>Main image</td>
    		<td>Image 2</td>
    		<td>Image 3</td>
    		<td>Image 4</td>
  		</tr>	
        <tr>
    		<td><img src="../images/saddles/<?php echo $product_row_id ?>_1.jpg" width="100" height="100" /></td>
    		<td><img src="../images/saddles/<?php echo $product_row_id ?>_2.jpg" width="100" height="100" /></td>
    		<td><img src="../images/saddles/<?php echo $product_row_id ?>_3.jpg" width="100" height="100" /></td>
    		<td><img src="../images/saddles/<?php echo $product_row_id ?>_4.jpg" width="100" height="100" /></td>
  		</tr>
	</table>

	</div>
	<!--content_container-->

</div> 
<!--page_container-->

</body>
</html>